package com.libre.auth.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.libre.auth.entity.LoginLog;
import com.libre.auth.service.LoginLogService;
import com.libre.common.base.BaseController;
import com.libre.common.utils.PageUtil;
import com.libre.common.utils.ResultUtil;
import com.libre.common.vo.PageVo;
import com.libre.common.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RequestMapping("/loginLog")
@RestController
public class LoginLogController extends BaseController {

    @Autowired
    private LoginLogService loginLogService;

    @GetMapping("/findPage")
    public Result<IPage<LoginLog>> findPage(@ModelAttribute PageVo pageVo, @ModelAttribute LoginLog loginLog) {
        IPage<LoginLog> page = loginLogService.findPage(PageUtil.initMpPage(pageVo), loginLog);
        return new ResultUtil<IPage<LoginLog>>().setData(page);
    }

    @GetMapping("/statistics")
    public Result statistics() {
        Map<String, Long> map = loginLogService.statistics();
        return new ResultUtil<>().setData(map);
    }

}
